﻿using LoA.Shared;
using LoA.Shared.Interfaces;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using System;

namespace LoA.Content.Pipeline {
	/// <summary>
	/// A TypeWriter for Map, which tells the content pipeline how to save the data in Map. 
	/// This class should match MapReader: whatever the writer writes, the reader should read. 
	/// </summary>
	[ContentTypeWriter]
	public class MapInfoWriter : ContentTypeWriter<MapInfo> {
		protected override void Write(ContentWriter output, MapInfo value) {
			output.Write(value.Region);
			output.Write(value.Position.X);
			output.Write(value.Position.Y);
			output.Write(value.Scale);
			output.Write(value.Width);
			output.Write(value.Height);

			if (value.HeightMap != null)
				foreach (float height in value.HeightMap) {
					output.Write(height);
				}
		}

		/// <summary>
		/// Tells the content pipeline what CLR type the data will be loaded into at runtime.
		/// </summary>
		public override string GetRuntimeType(TargetPlatform targetPlatform) {
			return typeof(IMapInfo).AssemblyQualifiedName;
		}


		/// <summary>
		/// Tells the content pipeline what worker type will be used to load the data.
		/// </summary>
		public override string GetRuntimeReader(TargetPlatform targetPlatform) {
			return typeof(MapInfo.MapInfoReader).AssemblyQualifiedName;
		}
	}
}